﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GestionePolveriLib.Facades;
using FrameworkLib.Facades.Paging;
using GestionePolveriLib.BL;
using System.IO;

namespace GestionePolveri2
{
    public partial class TestFacade : Form
    {
        MovimentiPagedFacade mf = null;
        int numberOfPages = 0;

        public TestFacade()
        {
            InitializeComponent();


            mf = new MovimentiPagedFacade(100);

            numberOfPages = mf.NumberOfPages;

            int[] m_elements = new int[numberOfPages];
            for (int i = 0; i < numberOfPages - 1; i++) m_elements.SetValue(i, i);

            this.dataNavigator1.DataSource = m_elements;

            this.pager11.NumberOfPages = numberOfPages;
            this.pager11.PageChanged += new EventHandler<NavigationEventArgs>(pager11_PageChanged);
            this.pager11.InitializeControl();
        }

        void pager11_PageChanged(object sender, NavigationEventArgs e)
        {
            switch (e.NavigationEventType)
            {
                case NavigationEventType.First:
                    mf.First();
                    break;
                case NavigationEventType.Next:
                    mf.Next();
                    break;
                case NavigationEventType.Previous:
                    mf.Previous();
                    break;
                case NavigationEventType.Last:
                    mf.Last();
                    break;
                case NavigationEventType.GotToPosition:
                    mf.PageNumber = e.Position;
                    break;
                default:
                    break;
            }

            button1_Click(this, EventArgs.Empty);
        }


        private void button1_Click(object sender, EventArgs e)
        {
            MovimentiPagedFacade mf = new MovimentiPagedFacade(100);
            List<Movimento2> data = mf.Getprova(); //.GetMovimenti();

            //string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            //string filename = string.Format(@"{0}\Prova.xls", path);

            //// prova export to excel 2
            //var report = new Report(data.ToReportSource());

            //report.DataFields["DataMovimento"].Hidden = true;
            //report.DataFields["CodCausale"].Hidden = true;
            //report.DataFields["NotePolvere"].Hidden = true;
            //DoddleReport.Writers.ExcelReportWriter ew = new DoddleReport.Writers.ExcelReportWriter();
            //using (FileStream fs = new FileStream(filename, FileMode.Create))
            //{
            //    ew.WriteReport(report, fs);
            //}




            // prova export to excel
            //FrameworkLib.Utilities.Export.CsvExporter<Movimento2> exp = new FrameworkLib.Utilities.Export.CsvExporter<Movimento2>("Movimento2", data);
            //exp.ToCsv(data, filename);



            //mf.LoadAsync((result) =>
            //{
            //    this.dataGridView1.DataSource = result;
            //});

            GestionePolveri2.DAL.GestionePolveriEntities context = new DAL.GestionePolveriEntities();
            var result = context.GetReportDirezionaleData(null, null, "sw300t", null, null, null, null, 1, 0);

            Console.WriteLine(result.Count());
        }

        private void TestFacade_Load(object sender, EventArgs e)
        {
            dataNavigator1.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(dataNavigator1_ButtonClick);
        }

        void dataNavigator1_ButtonClick(object sender, DevExpress.XtraEditors.NavigatorButtonClickEventArgs e)
        {
            e.Handled = true;

            switch (e.Button.ButtonType)
            {
                case DevExpress.XtraEditors.NavigatorButtonType.First:
                    this.dataNavigator1.Position=0;
                    mf.First();
                    break;
                case DevExpress.XtraEditors.NavigatorButtonType.Last:
                    this.dataNavigator1.Position=mf.NumberOfPages;
                    mf.Last();
                    break;
                case DevExpress.XtraEditors.NavigatorButtonType.NextPage:
                    if (this.dataNavigator1.Position < mf.NumberOfPages)
                    {
                        this.dataNavigator1.Position++;
                        mf.Next();
                    }
                    break;
                case DevExpress.XtraEditors.NavigatorButtonType.PrevPage:
                    if (this.dataNavigator1.Position > 0)
                    {
                        this.dataNavigator1.Position--;
                        mf.Previous();
                    }
                    break;
                 default:
                    break;
            }

            button1_Click(this, EventArgs.Empty);
        }
    }
}
